<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<title>输出报文初始化</title>

<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/style.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-editable.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/dropzone.css">

</head>

<body>
	<div th:insert="~{header :: copy}"></div>

	<div class="panel panel-default" style="padding-top: 80px;margin-left: 50px;margin-right: 50px;border: 0px">
		<div class="panel-heading" style="background: white;">
			<font size="5px">输出报文初始化</font>
		</div>
		<div class="panel-body">
			<table class="table table-bordered dchannel-table">
				<tr class="item-default">
					<td align="center" style="width: 20%;">
						<b><font>接口ID</font></b>
					    <select id="outputMessageName" size="30" style="width:100%;">
                		</select>
						<button type="submit" class="btn btn-primary" 
							onclick="clearMessageContent()" style="align-items: center;">删除</button>
					</td>
					<td align="center" style="width: 70%;">
						<b><font>报文内容</font></b>
			            <textarea id="outputMessageContent" style="width:100%; height: 512px">
			            </textarea>
			            <button type="submit" class="btn btn-primary" id="saveMessageContent"
							onclick="saveMessageContent()" style="align-items: center;">保存</button>
        			</td>
				</tr>
			</table>
		</div>
	</div>
	
</body>
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/jquery-ui.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap-table.js"></script>
<script src="bootstrap/js/bootstrap-editable.min.js"></script>
<script src="bootstrap/js/dropzone.js"></script>
<script src="bootstrap/js/bootstrap-table-editable.js"></script>
<script src="bootstrap/js/gateway.js"></script>
<script type="text/javascript">

function clearMessageContent() {
	var apiId = $("#outputMessageName").val();
	if(apiId == null || apiId == 'undefined') {
		Swal({
            title: '未选定需要删除内容的接口ID',
            type:"warning"
		});
		return;
	}
	
	$.ajax({
		type : "post",
		url : "/msgOutConf/deleteMsgOutConfContent",
		data : {
			apiId : apiId
		},
		async : true,
		success : function(data) {
			if (data.status == "SUCCESS") {
				Swal({
					title : '数据清除成功',
					type : "success"
				})
			} else {
				Swal({
					title : '数据清除失败：' + data.message,
					type : "error"
				});
			}
		},
		error : function() {
			alert("Ajax访问失败!");
		}
	});

}

	function saveMessageContent() {
		
		var value = $("#outputMessageContent").val();
		var apiId = $("#outputMessageName").val();
		
		if(apiId == null || apiId == 'undefined') {
			Swal({
                title: '请选择一个接口id',
                type:"warning"
			});
			return;
		}

		$.ajax({
				type : "post",
				url : "/msgOutConf/addMsgOutConfFromExample",
				data : {
					apiId : apiId,
					exampleData :value
				},
				async : true,
				success : function(data) {
					if (data.status == "SUCCESS") {
						Swal({
							title : '数据录入成功',
							type : "success"
						})
					} else {
						Swal({
							title : '数据录入失败：' + data.message,
							type : "error"
						});
					}
				},
				error : function() {
					alert("输入报文类型加载失败!");
				}
			});
	}

	function fillMessageContent(apiId) {

		/* 		$.ajax({
		 type:"post",
		 url:"/msgInConf/addMsgInConfFromExample",
		 data : {apiId:1,exampleData:1},
		 async : true,
		 success : function(data) {
		 if (data.status == "SUCCESS") {
		 Swal({
		 title: '数据录入成功',
		 type:"success"
		 })
		 } else {
		 Swal({
		 title: '数据录入失败：' + data.message,
		 type:"error"
		 });
		 }
		 },
		 error : function() {
		 alert("输入报文类型加载失败!");
		 }
		 }); */
	}

	$(function() {
		$("#outputMessageContent").html("");

		var paramTypeArray = new Array();

		//加载输入报文类型
		$.ajax({
			type : "get",
			url : "/apiDefine/getAllApiDefineIds",
			async : false,
			success : function(data) {
				var types = "";
				for (var i = 0; i < data.length; i++) {
					paramTypeArray[i] = {
						value : i,
						text : data[i]
					};
					types += "<option onclick='fillMessageContent(this.value)' value='"
							+ data[i] + "'>" + data[i] + "</option>";
				}
				$("#outputMessageName").append(types);
			},
			error : function() {
				alert("输入报文类型加载失败!");
			}
		});

	});
</script>

</html>